﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpTRI
{
        class Player : Character
        {
	    int mCamera;

	    struct CameraOffset
	    {
		    public Vec3D mPosition;
		    public Vec3D mRotation;
	    }

        public Player(int camera, uint speed, Color clr)
        {
            mCamera = camera;
            Attributes.MoveSpeed = speed;
            Xors3D.xEntityColor(Mesh, clr.R, clr.G, clr.B);
            DefaultCameraOffset();
        }

        CameraOffset DefaultCameraOffset()
        {
            CameraOffset offset;
            offset.mPosition = new Vec3D(0, 50, -50);
            offset.mRotation = new Vec3D(45, 0, 0);
            return offset;
        }

        void UpdateCamera()
        {
	        Vec3D camPosition = new Vec3D(Xors3D.xEntityX(Mesh, true), Xors3D.xEntityY(Mesh, true), Xors3D.xEntityZ(Mesh, true));
	        CameraOffset offset = DefaultCameraOffset();

	        camPosition += offset.mPosition;
	        Xors3D.xPositionEntity(mCamera, camPosition.X, camPosition.Y, camPosition.Z);
	
	        Vec3D camRotation = offset.mRotation;

	        Xors3D.xRotateEntity(mCamera, camRotation.X, camRotation.Y, camRotation.Z, true);
        }

        public override void Update()
        {
            if (mTarget != null)
            {
                if (InPosition(mTarget.Position))
                {
                    DealDamage(mTarget);
                }
                else
                {
                    Attack(mTarget);
                }
            }

            Move();
            UpdateCamera();

            if (mTarget != null)
            {
                Xors3D.xText(10,20,"Player HP: " + Attributes.Health);
                Xors3D.xText(10, 30, "target HP: " + mTarget.Attributes.Health);
            }
        }
    }
}
